﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using DotSpatial.Controls;

using System.Windows.Forms;

using System.Drawing;

using DotSpatial.Topology;


namespace HAGISV2
{

    /// <summary>
    /// 为所有的mapfunction 提供基类接口
    /// </summary>
    public class HMapFunction:MapFunction

    {
        public HMapFunction(IMap map):base(map)
        { 

        }


        InteractiveSystem _interactiveSystem;

        public InteractiveSystem InteractiveSystem
        {
            get { return _interactiveSystem; }
            set { _interactiveSystem = value; }
        }

        public bool _standBy;


     


        #region 需要统一的相关操作地方


        protected override void OnActivate()
        {
     
            _standBy = false;
            base.OnActivate();
        }

        /// <summary>
        /// Allows for new behavior during deactivation.
        /// </summary>
        protected override void OnDeactivate()
        {
            this.Enabled = false;
            if (_standBy) return;
            // Don't completely deactivate, but rather go into standby mode
            // where we draw only the content that we have actually locked in.
            _standBy = true;


        }

        protected override void OnDraw(MapDrawArgs e)
        {



            if (_standBy) return;

            base.OnDraw(e);
           
        }

        /// <summary>
        /// updates the auto-filling X and Y coordinates
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseMove(GeoMouseArgs e)
        {

            base.OnMouseMove(e);
            if (_standBy) return;


           

            
        }



     


        /// <summary>
        /// Handles the Mouse-Up situation
        /// </summary>
        /// <param name="e"></param>
        protected override void OnMouseUp(GeoMouseArgs e)
        {
            if (_standBy) return;

            base.OnMouseUp(e);




        


        }



      



        /// <summary>
        /// Occurs when this function is removed.
        /// </summary>
        protected override void OnUnload()
        {
            if (Enabled)
            {
              
            }


            Map.Invalidate();
        }



        protected override void OnMouseWheel(GeoMouseArgs e)
        {
            base.OnMouseWheel(e);

            Rectangle r = e.Map.MapFrame.View;
            int w = r.Width;
            int h = r.Height;

            int scale = 5;

            if (e.Delta < 0)
            {
                r.Inflate(r.Width / (2 * scale), r.Height / (scale * 2));
                r.X += w / (2 * scale) - e.X / (scale);
                r.Y += h / (2 * scale) - e.Y / (scale);
                //e.Map.MapFrame.View = r;
                //e.Map.MapFrame.ResetExtents();
                e.Map.MapFrame.ViewExtents = Map.PixelToProj(r);
            }
            else
            {
                r.Inflate(-r.Width / (4 * scale), -r.Height / (4 * scale));
                // The mouse cursor should anchor the geographic location during zoom.
                r.X += (e.X / (2 * scale)) - w / (4 * scale);
                r.Y += (e.Y / (2 * scale)) - h / (4 * scale);
                //e.Map.MapFrame.View = r;
                e.Map.MapFrame.ViewExtents = Map.PixelToProj(r);
            }

        }


        protected override void OnKeyUp(KeyEventArgs e)
        {
            base.OnKeyUp(e);

        }

        protected override void OnKeyDown(KeyEventArgs e)
        {
            base.OnKeyDown(e);

            if (this._standBy) return;

            if (e.KeyCode == Keys.Escape)
            {


                this.Enabled = false;

                this.Map.Invalidate();
             

                this._interactiveSystem.SetMapMode(MAPMODE.NONE);
                




            }
        }


       


        #endregion

        #region 受保护的方法

        

        #endregion


    }
}
